package com.clps.algorithm.chapter03.不含重复字符的最长子字符串;

public class demo02 {

    public static void main(String[] args) {


    }

    public  int lengThOfLongestSubString(String s){
        int[] counts = new int[256];
        int longest = s.length()>0?1:0;
        int countDup = 0;

        for (int i = 0,j = -1; i <s.length() ; i++) {
            counts[s.charAt(i)]++;
            if(counts[s.charAt(i)] == 2){
                countDup++;
            }

            while (countDup>0){
                ++j;
                counts[s.charAt(j)]--;
                if(counts[s.charAt(j)] == 1){
                    countDup--;
                }
            }

            longest = Math.max(i-j,longest);
        }
        return  longest;
    }


}
